package com.project.class4_6;

/**
 * 线程死锁
 */
public class DieBlock {
    public static void main(String[] args) {
        MyOBJ m1=new MyOBJ("吴强");
        MyOBJ m2= new MyOBJ("魏婷");
        new Thread(){
            public void run(){
                synchronized (m1){
                    try {
                        Thread.sleep(300);
                        m2.speak();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
        /**
         * 第二个线程
         */
        new Thread(){
            public void run(){
                synchronized (m2){
                    try {
                        Thread.sleep(300);
                        m1.speak();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
        }}}.start();
    }
}
class MyOBJ{
    private String name;
    public MyOBJ(String name){
        this.name=name;
        System.out.println("创建一个   "+name+"   对象");
    }
    public synchronized void speak(){
        System.out.println("执行   "+name+"  speak方法");
    }
}